#include <iostream>
#include <stack>
#include <vector>
#include <queue>
using namespace std;

int const maxn = 1001;
bool vis[maxn];
int dis[maxn], path[maxn];
int n, m;


vector<vector<int> > graph;

int bfs(int x)
{
	queue<int> q;
	q.push(x);
	vis[x] = true;
	path[x] = -1;
	dis[n-1] = -2;

	typedef vector<int>::iterator e_it;
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (e_it it = graph[u].begin(); it != graph[u].end(); ++it) {
			int v = *it;
			if (!vis[v]) {
				dis[v] = dis[u]+1;
				path[v] = u;
				vis[v] = true;
				q.push(v);
			}
		}
	}
	return dis[n-1] + 1;
}

int main()
{
	cin >> m >> n;
	graph.resize(n);
	for (int i = 0, x, y; i < m; i++) {
		cin >> x >> y;
		x--; y--;
		graph[x].push_back(y);
	}

	int t = bfs(0);
	cout << t << "\n";
	if (t != -1) {
		stack<int> ans;
		for (int i = n-1; i != -1; i = path[i]) ans.push(i+1);
		for (; !ans.empty(); ans.pop()) cout << ans.top() << "\n";
	}
}

